package com.tarena.lbs.basic.web.controller;


import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.pojo.param.AddAdminParam;
import com.tarena.lbs.basic.web.pojo.param.QueryAdminParam;
import com.tarena.lbs.basic.web.service.AdminService;
import com.tarena.lbs.common.passport.encoder.JwtEncoder;
import com.tarena.lbs.common.passport.principle.UserPrinciple;
import com.tarena.lbs.pojo.basic.vo.AdminVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class AdminController {


    @Autowired
    private AdminService adminService;


    @GetMapping("/admin/basic/role/detail")
    public Result<AdminVO> getAdminDetailInfo(@RequestHeader(value = "Authorization") String jwt) throws BusinessException {
        log.debug("jwt:{}",jwt);
        AdminVO adminVO = adminService.getAdminDetailInfo(jwt);
        return new  Result<>(adminVO);
    }


    @GetMapping("/admin/basic/role/list")
    public Result<PageResult<AdminVO>> getAdminPage(QueryAdminParam queryAdminParam){
        log.debug("查询后台账号列表");
        PageResult<AdminVO> pageResult = adminService.getAdminPage(queryAdminParam);
        return new Result<>(pageResult);
    }


    @PostMapping("/admin/basic/role/add")
    public Result<Void> addAdmin(AddAdminParam addAdminParam) throws BusinessException {
        //使用无参构造返回
        adminService.addAdmin(addAdminParam);
        return Result.success();
    }


}
